package com.party.admin.task;

import com.party.common.utils.DateUtils;
import com.party.core.model.charge.PackageMember;
import com.party.core.service.charge.IPackageMemberService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

/**
 * 将昨天未支付的系统购买订单设置为已失效
 * Created by hqh
 *
 * @date 2019/6/26 0026
 * @time 15:03
 */

@Component(value = "quartzcleanSystemUnpaidOrder")
public class QuartzcleanSystemUnpaidOrder {

    @Autowired
    private IPackageMemberService packageMemberService;

    protected static Logger logger = LoggerFactory.getLogger(QuartzcleanSystemUnpaidOrder.class);

    public void clear() {
        long staTime = System.currentTimeMillis();
        logger.info("开始执行---系统购买订单设置为已失效--的任务——————开始时间：："+staTime);
        try {
            //获取今天的开始时间
            String f1StrDay = DateUtils.formatDate(new Date(), "yyyy-MM-dd") + " 00:00:00";

            List<PackageMember> packageMembers = packageMemberService.queryUnpaidPayPMList(f1StrDay);
            for (PackageMember pm : packageMembers) {
                pm.setStatus(2);
                packageMemberService.update(pm);
            }
        } catch (Exception e) {
            logger.error("系统购买订单设置为已失效---------异常", e);
        }
        long endTime = System.currentTimeMillis()-staTime;
        logger.info("任务结束---系统购买订单设置为已失效--的任务——————用时：："+endTime);
    }
}
